(ns pe.p21
  (:use pe.digits))

(defn d [n]
  (apply + (prop-divisors n)))

(defn amicable? [x]
  (let [dx (d x) dy (d dx)]
    (and (not (= x dx)) (= dy x))))

(defn all-amicables [to]
  (distinct (mapcat identity (for [x (range 1 to) :when (amicable? x)] [x (d x)]))))
